home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / createPaintingMenuItems.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.1 KB  |  203 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. global string $ListPaintableItem[];
  18. global int    $ListPaintableRegistInit;
  19.  
  20. global proc selectPaintableItem(
  21.     string $obj,
  22.     string $node,
  23.     string $attr
  24. )
  25. {
  26.     // get the surface list
  27.     string $surfaceList[], $cmd;
  28.     $cmd = "listPaintable -getsurface \"" + $node + "\"";
  29.     $surfaceList = `eval $cmd`;
  30.  
  31.     // select the surface
  32.     select -cl;
  33.     $cmd = "select -r ";
  34.     for( $s in $surfaceList ) {
  35.         // Avoid selecting intermediate objects
  36.         //
  37.         int $io = `getAttr ($s+".io")`;
  38.         if ($io == 0) {
  39.             $cmd += $s + " ";
  40.         }
  41.     }
  42.     eval $cmd;
  43.  
  44.     // set the current Tool
  45.     $cmd = "listPaintable -getcontext \"" + $node + "\"";
  46.     string $context = `eval $cmd`;
  47.  
  48.     if( "skinPaintContext" == $context ) {
  49.         skinPaintToolScript( 4 );
  50.     }
  51.     else if( "polyClrVertPaintContext" == $context ) {
  52.         polyClrVertPaintToolScript( 4 );
  53.     }
  54.     else {
  55.         attrPaintToolScript( 4 );
  56.     }
  57.  
  58.     // Now, `currentCtx` and $context are the same...
  59.  
  60.     // set the selection node and attr
  61.     $s = $obj + "." + $attr;
  62.     attrPaintCtx -e -oth $obj $context;
  63.     attrPaintCtx -e -ath $s $context;
  64.     attrPaintCtx -e -sdn $node $context;
  65. }
  66.  
  67.  
  68. global proc createPaintingAttrItems(
  69.     string         $parent,
  70.     int            $index,
  71.     string         $obj 
  72. )
  73. //
  74. //    Description:
  75. //         Creates a menu that shows all the paintable attributes
  76. // 
  77. {
  78.     global string $ListPaintableItem[];
  79.  
  80.     popupMenu -e -dai $parent;
  81.     setParent -menu $parent;
  82.  
  83.      string $menu, $buffer[];
  84.     int $size = size($ListPaintableItem);
  85.     int $i;
  86.     for( $i = $index; $i < $size; $i++ ) {
  87.         tokenize( $ListPaintableItem[$i], ".", $buffer );
  88.         if( $obj != $buffer[1] ) {
  89.             break;
  90.         }
  91.         else {
  92.             $menu = `menuItem -l $buffer[2]`;
  93.             menuItem -e -c ( "selectPaintableItem " + $buffer[0] + " " + $obj + " " + $buffer[2] ) $menu;
  94.             setParent -m $parent;
  95.         }
  96.     }
  97. }
  98.  
  99.  
  100. global proc createPaintingMenuItems(
  101.     string         $parent, 
  102.     string         $item
  103. )
  104. //
  105. //    Description:
  106. //         Creates a menu that shows all the paintable objects and 
  107. //        their attributes in the currenct selection
  108. // 
  109. {
  110.      string $shape = "";
  111.  
  112.      // Look at the shape child of this object
  113.      //
  114.      string $object[] = `listRelatives -path -s $item`;
  115.  
  116.      int $i;
  117.      for ($i = 0; $i < size($object); ++$i) {
  118.         if ( (`nodeType $object[$i]` == "nurbsSurface") ||
  119.              (`nodeType $object[$i]` == "mesh") ) {
  120.              if (getAttr($object[$i] + ".io") == 0) {
  121.                  $shape = $object[$i];
  122.                  break;
  123.              }
  124.         } 
  125.      }
  126.  
  127.  
  128.     //==================================================================
  129.     // If the $shape is a cloth mesh, set up cloth property paint tool
  130.     // differently and return from here. We check if mayaCloth is
  131.     // licensed by checking pluginInfo. Actually, if without mayaCloth
  132.     // plugin loaded, we can not paint on the cloth mesh.
  133.     //
  134.     if( `pluginInfo -q -l "CpClothPlugin"` )
  135.     {
  136.         // isClothMesh is a script defined in clothPaintCallback.
  137.         //
  138.         string $srcString = "source clothPaintCallback";
  139.         eval $srcString;
  140.  
  141.         if( isClothMesh($shape) )
  142.         {
  143.             createClothPaintMenuItems( $parent, $shape );
  144.             return;
  145.         }
  146.     }
  147.     //==================================================================
  148.  
  149.     // if there is no shape, then just return
  150.     //
  151.     if( $shape == "" ) {
  152.         menuItem -l "(empty)" -en false;
  153.         return;
  154.     }
  155.  
  156.     global int    $ListPaintableRegistInit;
  157.     global string $ListPaintableItem[];
  158.  
  159.     // initialize the regist list if necessary
  160.     // 
  161.     if( !$ListPaintableRegistInit ) {
  162.         ListPaintableRegist();
  163.         $ListPaintableRegistInit = true;
  164.     }
  165.  
  166.     clear $ListPaintableItem;
  167.  
  168.     popupMenu -e -dai $parent;
  169.     setParent -menu $parent;
  170.  
  171.      string $cmd;
  172.      if( $shape == $item ) {
  173.          $cmd = "listPaintable -re1 " + $shape;
  174.      }
  175.      else {
  176.          $cmd = "listPaintable -re2 " + $item + " " + $shape;
  177.      }
  178.      $ListPaintableItem = `eval $cmd`;
  179.  
  180.  
  181.      string $obj, $buffer[];
  182.      int    $i;
  183.      int    $size = size( $ListPaintableItem );
  184.  
  185.     if( $size == 0 ) {
  186.         menuItem -l "(empty)" -en false;
  187.     }
  188.     else {    
  189.         string $menu;
  190.  
  191.         for( $i = 0, $obj = ""; $i < $size; $i++ ) {
  192.             tokenize( $ListPaintableItem[$i], ".", $buffer );
  193.             if( $obj != $buffer[1] ) {
  194.                 $obj = $buffer[1];
  195.                 // new paintable obj
  196.                 $menu = `menuItem -subMenu true -l $obj`;
  197.                 menu -e -pmc ( "createPaintingAttrItems \""+$menu+"\" " + $i + " " + $obj ) $menu;
  198.                 setParent -m $parent;
  199.             }
  200.         }
  201.     }
  202. }
  203.